
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[siodge_split_string]'))
drop function [dbo].[siodge_split_string]
GO


CREATE		function			[dbo].[siodge_split_string] 
								(@slicer			varchar(50),
								@string				varchar(8000)) 
returns		@tb_return			table
								(id					int identity,
								[values]			varchar(1000))

as
begin

  declare	@str_to_get			varchar(1000)
  declare	@cont				int
 
  set		@string				= @string + @slicer
  set		@cont				= len(@string)

  if		charindex(@slicer, @string) = 0 
  begin
	insert	into				@tb_return
	select	@string
 
	return
  end

  while		@cont				> 0
  begin
 
	set		@str_to_get			= substring(@string, 1, charindex(@slicer, @string) + len(@slicer) - 1)
	set		@string				= substring(@string, (charindex(@slicer, @string) + len(@slicer)) , len(@string) - len(@str_to_get))
	set		@cont				= len(@string)
 
	insert	into				@tb_return 
	select	ltrim(rtrim(replace(@str_to_get, @slicer, '')))
 
  end

  return
end

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO
